document.addEventListener('visibilitychange', function () {
    if (document.visibilityState == 'hidden') {
        normal_title = document.title;
        document.title = '≧◉◡◉≦我藏好了哦！山野千里，你是我藏在星星里的浪漫。';
    } else document.title = normal_title;
});


/*页面点击有小♥心*/
!function(e, t, a) {
        function n() {
            c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 500%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),
                o(),
                r()
        }
        function r() {
            for (var e = 0; e < d.length; e++) d[e].alpha <= 0 ? (t.body.removeChild(d[e].el), d.splice(e, 1)) : (d[e].y--, d[e].scale += .004, d[e].alpha -= .013, d[e].el.style.cssText = "left:" + d[e].x + "px;top:" + d[e].y + "px;opacity:" + d[e].alpha + ";transform:scale(" + d[e].scale + "," + d[e].scale + ") rotate(45deg);background:" + d[e].color + ";z-index:99999");
            requestAnimationFrame(r)
        }
        function o() {
            var t = "function" == typeof e.onclick && e.onclick;
            e.onclick = function(e) {
                t && t(),
                    i(e)
            }
        }
        function i(e) {
            var a = t.createElement("div");
            a.className = "heart",
                d.push({
                    el: a,
                    x: e.clientX - 5,
                    y: e.clientY - 5,
                    scale: 1,
                    alpha: 1,
                    color: s()
                }),
                t.body.appendChild(a)
        }
        function c(e) {
            var a = t.createElement("style");
            a.type = "text/css";
            try {
                a.appendChild(t.createTextNode(e))
            } catch(t) {
                a.styleSheet.cssText = e
            }
            t.getElementsByTagName("head")[0].appendChild(a)
        }
        function s() {
            return "rgb(" + ~~ (255 * Math.random()) + "," + ~~ (255 * Math.random()) + "," + ~~ (255 * Math.random()) + ")"
        }
        var d = [];
        e.requestAnimationFrame = function() {
            return e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame ||
                function(e) {
                    setTimeout(e, 1e3 / 60)
                }
        } (),
            n()
    } (window, document);

/*动态输出一言*/
function yiyan(){
    $.ajax({
        type: 'GET',
        url: 'https://v1.hitokoto.cn',
        dataType: 'json',
        success (data) {
            var text=data.hitokoto;
            var binft = function (r) {
                function t() {
                    return b[Math.floor(Math.random() * b.length)]
                }
                function e() {
                    return String.fromCharCode(94 * Math.random() + 33)
                }
                function n(r) {
                    for (var n = document.createDocumentFragment(), i = 0; r > i; i++) {
                        var l = document.createElement("span");
                        l.textContent = e(), l.style.color = t(), n.appendChild(l)
                    }
                    return n
                }
                function i() {
                    var t = o[c.skillI];
                    c.step ? c.step-- : (c.step = g, c.prefixP < l.length ? (c.prefixP >= 0 && (c.text += l[c.prefixP]), c.prefixP++) : "forward" === c.direction ? c.skillP < t.length ? (c.text += t[c.skillP], c.skillP++) : c.delay ? c.delay-- : (c.direction = "backward", c.delay = a) : c.skillP > 0 ? (c.text = c.text.slice(0, -1), c.skillP--) : (c.skillI = (c.skillI + 1) % o.length, c.direction = "forward")), r.textContent = c.text, r.appendChild(n(c.prefixP < l.length ? Math.min(s, s + c.prefixP) : Math.min(s, t.length - c.skillP))), setTimeout(i, d)
                }
                var l = "",
                    o = [text].map(function (r) {
                        return r + ""
                    }),
                    a = 2,
                    g = 1,
                    s = 5,
                    d = 75,
                    b = ["rgb(110,64,170)", "rgb(150,61,179)", "rgb(191,60,175)", "rgb(228,65,157)", "rgb(254,75,131)", "rgb(255,94,99)", "rgb(255,120,71)", "rgb(251,150,51)", "rgb(226,183,47)", "rgb(198,214,60)", "rgb(175,240,91)", "rgb(127,246,88)", "rgb(82,246,103)", "rgb(48,239,130)", "rgb(29,223,163)", "rgb(26,199,194)", "rgb(35,171,216)", "rgb(54,140,225)", "rgb(76,110,219)", "rgb(96,84,200)"],
                    c = {
                        text: "",
                        prefixP: -s,
                        skillI: 0,
                        skillP: 0,
                        direction: "forward",
                        delay: a,
                        step: g
                    };
                i()
            };
            binft(document.getElementById('binft'));
        },
        error(jqXHR, textStatus, errorThrown) {
            // 错误信息处理
            console.error(textStatus, errorThrown)
        }
    })
}

<!--网站运行时间-->
function show_runtime(createTime) {
    // window.setTimeout("show_runtime()", 1000);
    X = new Date(Date.parse(createTime.replace(/-/g,  "/")));
    Y = new Date();
    T = (Y.getTime() - X.getTime());
    M = 24 * 60 * 60 * 1000;
    a = T / M;
    A = Math.floor(a);
    // b = (a - A) * 24;
    // B = Math.floor(b);
    // c = (b - B) * 60;
    // C = Math.floor((b - B) * 60);
    // D = Math.floor((c - C) * 60);
    // runtime.innerHTML = "" + A + "天" + B + "小时" + C + "分" + D + "秒";
    runtime.innerHTML = ""+ A + "天";

    startYear = X.getFullYear();
    endYear = Y.getFullYear();
    runtime_start.innerHTML = startYear;
    runtime_end.innerHTML = endYear;

}

$(function(){
    //首页折叠菜单
    $(document).ready(function(){
        $('.ui.accordion').accordion({duration:'click'});
    });


    // 获取系统创建时间
    $.ajax({
        type: 'GET',
        async: true, //修改此方法为同步，解决ajax是异步请求问题
        url: '/getCreateTime',
        dataType: 'json',
        success(data) {
            if(data.code == 200){
                show_runtime(data.data.createTime);
            }
        },
        error(jqXHR, textStatus, errorThrown) {
            // 错误信息处理
            console.error(textStatus, errorThrown)
        }
    });

    // 获取系统统计代码
    $.ajax({
        type: 'GET',
        async: true, //修改此方法为同步，解决ajax是异步请求问题
        url: '/getTongji',
        dataType: 'json',
        success(data) {
            if(data.code == 200){
                $("#tongji").append(data.data.tongji);
                // console.log(data.data.tongji)
            }
        },
        error(jqXHR, textStatus, errorThrown) {
            // 错误信息处理
            console.error(textStatus, errorThrown)
        }
    });


    /*背景*/
    var c = document.getElementById('evanyou'),
        x = c.getContext('2d'),
        pr = window.devicePixelRatio || 1,
        w = window.innerWidth,
        h = window.innerHeight,
        f = 90,
        q,
        m = Math,
        r = 0,
        u = m.PI * 2,
        v = m.cos,
        z = m.random;
    c.width = w * pr;
    c.height = h * pr;
    x.scale(pr, pr);
    x.globalAlpha = 0.6;
    function evanyou() {
        x.clearRect(0, 0, w, h)
        q = [{ x: 0, y: h * .7 + f }, { x: 0, y: h * .7 - f }]
        while (q[1].x < w + f) d(q[0], q[1])
    }
    function d(i,j) {
        x.beginPath()
        x.moveTo(i.x, i.y)
        x.lineTo(j.x, j.y)
        var k = j.x + (z() * 2 - 0.25) * f,
            n = y(j.y)
        x.lineTo(k, n)
        x.closePath()
        r -= u / -50
        x.fillStyle = '#' + (v(r) * 127 + 128 << 16 | v(r + u/ 3) * 127 + 128 << 8 | v(r + u/ 3 * 2) * 127 + 128).toString(16)
        x.fill()
        q[0] = q[1]
        q[1] = { x: k, y: n }
    }
    function y(p) {
        var t = p + (z() * 2 - 1.1) * f
        return (t > h || t < 0) ? y(p) : t
    }
    document.onclick = evanyou
    document.ontouchstart = evanyou
    evanyou();


    //返回顶部

    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide-item');
    });

    $('#totop-button').click(function () {
        $(window).scrollTo(0, 300);
    });

    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
        }
    })


})